// pages/azclassify/azclassify.js
import * as api from '../../utils/api.js';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    list: []
  },
  onChange(event){
    const that = this
    const active = event.detail.name
    const status = active == 0 ? 1 : 2
    this.setData({active})
    setTimeout(() => that.workerInstallOrderList(status),50);
  },
  workerInstallOrderList(status = null){
    const that = this
    let  list = this.data.list
    const curStatus = this.data.active == 0 ? 1 : 2
    status = status == null ? curStatus : status
    const childList = list && list[status] ? list[status] : null
    const current_page = childList ? childList.current_page : 1
    const last_page = childList ? childList.last_page : 1
    if (childList && current_page == last_page) {
      // console.log('No more data')
      return false
    }
    const page = childList && current_page < last_page ? current_page + 1 : 1
    api.workerInstallOrderList(status,page)
      .then(res => {
        if (childList && current_page < res.data.current_page) {
          list[status]['data'] = childList.data.concat(res.data.data)
          list[status]['current_page'] = res.data.current_page
        } else {
          list[status] = res.data
        }
        that.setData({
          list
        })
      }).catch(err => console.log(err))
  },
  detail:function(e){
    wx.navigateTo({
      url: '/pages/worker/installOrderDetail?order_sn='+e.currentTarget.dataset.order_sn,
    })
  },

  onLoad(options) {
    
  },

  map: function (e) {
    wx.navigateTo({
      url: "/pages/worker/map?type=install"
    })
  },
  
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.workerInstallOrderList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.workerInstallOrderList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})